"""
@File    : ens_instance_sdg_monitor_01.py
@Author  : timo.tan
@Time    : 2025/07/28 12:15 
"""
"""
@File    : ens_instance_sdg_monitor.py
@Author  : timo.tan
@Time    : 2025/07/24 18:31 
"""
import sys
import json
import time
from typing import List
from alibabacloud_ens20171110.client import Client as Ens20171110Client
from alibabacloud_credentials.client import Client as CredentialClient, Config
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ens20171110 import models as ens_20171110_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient

from tools.log_util import INFO


class EnsInstanceMonitor:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> Ens20171110Client:
        """
        使用凭据初始化账号Client
        @return: Client
        @throws Exception
        """
        # SIT 环境
        credentialsConfig = Config(
            type="access_key",
            # access_key_id="LTAI5tSN4cEk4FzE9hBxk88x",
            # access_key_secret="ZhRlXyhuxNSpF9bSqNmOXlWr3Vav9D",
            access_key_id="LTAI5tPknNicjk1km64yEPvn",
            access_key_secret="8FMOyIzymGTPEYUufZULlcw62dlTUt",)
        # 使用AK 初始化Credentials Client。
        credentialClient = CredentialClient(credentialsConfig)

        config = open_api_models.Config(credential=credentialClient)
        config.endpoint = "ens.aliyuncs.com"
        return Ens20171110Client(config)

    @staticmethod
    def main(
            args: List[str],
    ) -> None:
        client = EnsInstanceMonitor.create_client()
        describe_instance_sdgstatus_request = (
            ens_20171110_models.DescribeInstanceSDGStatusRequest(args[0])
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            response: ens_20171110_models.DescribeInstanceSDGStatusResponse = (
                client.describe_instance_sdgstatus_with_options(
                    describe_instance_sdgstatus_request, runtime
                )
            )
            INFO.logger.info(json.dumps(response.to_map(), ensure_ascii=True, indent=4))

        except Exception as error:
            # 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == "__main__":
    INFO.logger.info(sys.argv)
    while True:
        # EnsInstanceMonitor.main(sys.argv[1:])
        # EnsInstanceMonitor.main(["aic-54eq14cetsyk3ykap1anugn65-1"])
        # EnsInstanceMonitor.main(["aic-vr3g24a060x011-3-04-3-ofxbycyc"]) # 195828 的实例
        EnsInstanceMonitor.main(["aic-54nsndtbzmcoxashriy9fygp4-1"])  # 355134 的实例
        time.sleep(50)

        # old = 'sdg-629e63c9faa40ec0b6aa5652a57a6079'
        # old = 'sdg-cacb7fef75b56344cce38f84e2078cde'

        # new = 'sdg - 28f1ecfa50e2695e21329f647100a639'
